<!-- 
 *  Copyright [2014] UW-Parkside
 * Authors: Jasmine Griffiths, Matthew Zygowicz, Armando Narvaez
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
-->

<!-- This is the page for adding routes.  It uses the Models to process and display the data 
     IMPORTANT: Classes and IDs used in the HTML are used in the SampleJS.js file for resizing -->
<body>
    <?php
	/*
	 * Display an error message, if there is one
	*/
    if (strlen($errMsg) > 0) {
        print "<div class='alert-box error'>";
        print "<strong>Error!</strong>";
        print "<p>";
        print $errMsg;
        print "</p>";
        print "</div>";
    }
	/*
	 * Display a success message, if there is one
	*/
    if (strlen($successMsg) > 0) {
        print "<div class='alert-box success'>";
        print "<strong>Success!</strong>";
        print "<p>";
        print $successMsg;
        print "</p>";
        print "</div>";
    }
    ?>
	
    <div id="container"><!--Start Container -->
		
        <div id="mainContent"><!--Start mainContent -->		
		
            <div><!-- Start Header -->
                <p><img src="/resources/img/logoBanner.png" alt="KAT Banner"/></p>
                <hr />
                <?php include 'navigation.php'; ?>
                <p> Welcome to the Kenosha Area Transit Application manager.</p>
            </div><!-- End Header -->	
			
            <div><!-- Start Sub-Heading -->
                <form>
                    <p>Filter</p>
                    <p>
                       <input type="text" id="searchFilter" placeholder="Location, Day, or Time" />  <!-- <input type="reset" value="Clear"> -->
                    </p>
                </form>
            </div><!-- End Sub-Heading -->
          
            <?php
			/*
             *Check if user has permission to use the sticky window,
			 *to add routes
			*/
            if ($_SESSION['realm'] != 'View') { //Check user's permission level
                echo "<div id='reducedResolution'>";  //reducedSolution is used for resizing, must keep name!
                include 'hiddenRouteBoxMin.php'; //Sticky window is a separate view 
                print "Editing Route"; 
                print "<a href = '/index.php/kat/route'>";
                print "<input id = 'doneButton2' class='reducedSize right blue button' value=\"Done Editing\" name='done' type='submit'>";
                print "</a>";
                echo "</div>";
            }

            include 'pagination.php';
            ?> 
            
            <table id="minimalistTable" class="tableizer-table"><!--Start table for route information --> 
                <thead class="tableizer-firstrow">
                <th class="hidden">id</th>
                <th>Location</th>
                <th>Day</th>
                <th>Time</th>
                <th>Direction</th>
                </thead>
                <tbody id = "tableFilter"> 
                    <?php
                    if ($routeArray != '') { //Process the route results
                        foreach ($routeArray as $data) {//Display the data
			    if(strlen($data['time']) > 3){
                                $time = substr($data['time'],0,2) . ":" . substr($data['time'],2) .":00";
                            }else if (strlen($data['time']) == 3){
                               $time = "0" . substr($data['time'],0,1) . ":" . substr($data['time'],1) .":00";
                            }
			    else if (strlen($data['time']) == 2){
                               $time = "00:" . $data['time'] .":00";
                            }
			    else if (strlen($data['time']) == 1){
                               $time = "00:0" . $data['time'] .":00";
                            }
                            $human_time = date("g:iA", strtotime($time));
                            print "<tr class='clickable' onclick=\"populateAddRouteForm('{$data['_id']}','{$data['location']}','{$data['day']}','{$data['time']}','{$data['direction']}' );\">";
                            print "<td class='hidden'>{$data['_id']}</td>";
                            print "<td>{$data['location']}</td>";
                            print "<td>{$data['day']}</td>";
                            print "<td>{$human_time}</td>";
                            print "<td>{$data['direction']}</td>";
                            print "</tr>";
                        }
                    }
                    ?>
                </tbody>
            </table><!-- End table for route information -->
            </div> <!-- Closes pagination div -->
        </div><!-- End mainContent -->	
    </div><!-- End container -->
  
   
    <div id="sideContent"><!-- Start sideContent -->
        <?php
		/*
		 * Displays the side content if the user has editing permissions.
		*/
        if ($_SESSION['realm'] != 'View') { // Display the sticky box, if they have credentials
            echo "<div id='sticker' class = 'stick'>";// id's and classes are used for resizing.
            include 'hiddenRouteBox.php';//Pull in the view
            echo "</div>";
        }
        ?> 
         <?php 
		 /*
		  * Display another sticky window when the user is editing a route
		  * A button is created to allow the user to click when done adding.
		 */
        if(isset($_SESSION['mode'])){//Check if 'editmode' is set
            print " <div id='editSideContent'>";
            print "<div class='stick' id='editSticker'>";
            print "<form action = '/index.php/kat/route' method = 'POST'>";
            print "<p><strong>Route $_POST[routenumber]</strong></p>";
            print "<hr />";
            print "<p>You are editing Route $_POST[routenumber]</p>";
            print "<input id = 'doneButton' class='reducedSize right blue button' value=\"Done Editing\" name='done' type='submit'>";
            print "</form>";
            print "</div>";
            print "</div>";
        }
        ?>
                
   
    </div><!--End sideContent --> 
    <div class="clear"></div>

<script>
    (function($) {
        $('#pagination').simplePagination();
    })(jQuery);
</script>
</body>

<div id="site-footer">Kenosha Area Transit Manager developed by UW-Parkside 2014</div><!-- Footer -->